home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 June: Reference Library / Dev.CD Jun 95 / Dev.CD Jun 95.toast / What's New? / New System Software Extensions / QuickDraw 3D ß / Programming / SampleCode / CommonSample / MyErrorHandler.c < prev    next >
Encoding:
Text File  |  1995-03-31  |  10.5 KB  |  227 lines  |  [TEXT/MPCC]

  1. // qd3d sample code - Nick Thompson DEVSUPPORT, 23rd March 1995
  2. //
  3. // © 1995, Apple Computer Inc., All Rights Reserved
  4. //
  5. #include "QD3D.h"
  6. #include "QD3DErrors.h"
  7.  
  8. #include "MyErrorHandler.h"
  9.  
  10. // define a table for all of the QuickDraw 3D error codes
  11. struct {
  12.     TQ3Warning    theWarning ;
  13.     char        *theString ;
  14. } warningTable[] = {
  15.     /* General System */
  16.     kQ3WarningInternalException,                    "kQ3WarningInternalException",
  17.     /* Object Warnings */
  18.     kQ3WarningNoObjectSupportForDuplicateMethod,    "kQ3WarningNoObjectSupportForDuplicateMethod",
  19.     kQ3WarningNoObjectSupportForWriteMethod,        "kQ3WarningNoObjectSupportForWriteMethod",
  20.     kQ3WarningNoObjectSupportForReadMethod,            "kQ3WarningNoObjectSupportForReadMethod",
  21.     kQ3WarningNoObjectSupportForDrawMethod,            "kQ3WarningNoObjectSupportForDrawMethod",
  22.     kQ3WarningUnknownElementType,                    "kQ3WarningUnknownElementType",
  23.     kQ3WarningTypeAndMethodAlreadyDefined,            "kQ3WarningTypeAndMethodAlreadyDefined",
  24.     kQ3WarningTypeIsOutOfRange,                        "kQ3WarningTypeIsOutOfRange",
  25.     kQ3WarningTypeHasNotBeenRegistered,                "kQ3WarningTypeHasNotBeenRegistered",
  26.     /* IO Warnings */
  27.     kQ3WarningFilePointerResolutionFailed,            "kQ3WarningFilePointerResolutionFailed",
  28.     kQ3WarningStringExceedsMaximumLength,            "kQ3WarningStringExceedsMaximumLength",
  29.     /* Memory Warnings */
  30.     kQ3WarningLowMemory,                            "kQ3WarningLowMemory",
  31.     kQ3WarningPossibleMemoryLeak,                    "kQ3WarningPossibleMemoryLeak",
  32.     /* View Warnings */
  33.     kQ3WarningViewTraversalInProgress,                "kQ3WarningViewTraversalInProgress",
  34.     kQ3WarningNonInvertibleMatrix,                    "kQ3WarningNonInvertibleMatrix",
  35.     /* Quaternion Warning */
  36.     kQ3WarningQuaternionEntriesAreZero,                "kQ3WarningQuaternionEntriesAreZero",
  37.     /* Renderer Warning */
  38.     kQ3WarningFunctionalityNotSupported,            "kQ3WarningFunctionalityNotSupported",
  39.     kQ3WarningLastWarning,                            "kQ3WarningLastWarning"
  40. } ;
  41.  
  42.  
  43. struct {
  44.     TQ3Error    theError ;
  45.     char    *theString ;
  46. } errorTable[] = {
  47.     /* Fatal Errors */
  48.     kQ3ErrorInternalError,                        "kQ3ErrorInternalError",
  49.     kQ3ErrorNoRecovery,                            "kQ3ErrorNoRecovery",
  50.     kQ3ErrorLastFatalError,                        "kQ3ErrorLastFatalError",
  51.     /* System Errors */
  52.     kQ3ErrorNotInitialized,                        "kQ3ErrorNotInitialized",
  53.     kQ3ErrorAlreadyInitialized,                    "kQ3ErrorAlreadyInitialized",
  54.     kQ3ErrorUnimplemented,                        "kQ3ErrorUnimplemented",
  55.     kQ3ErrorRegistrationFailed,                    "kQ3ErrorRegistrationFailed",
  56.     /* OS Errors */
  57.     kQ3ErrorUnixError,                            "kQ3ErrorUnixError",
  58.     kQ3ErrorMacintoshError,                        "kQ3ErrorMacintoshError",
  59.     kQ3ErrorX11Error,                            "kQ3ErrorX11Error",
  60.     /* Memory Errors */
  61.     kQ3ErrorMemoryLeak,                            "kQ3ErrorMemoryLeak",
  62.     kQ3ErrorOutOfMemory,                        "kQ3ErrorOutOfMemory",
  63.     /* Parameter errors */
  64.     kQ3ErrorNULLParameter,                        "kQ3ErrorNULLParameter",
  65.     kQ3ErrorParameterOutOfRange,                "kQ3ErrorParameterOutOfRange",
  66.     kQ3ErrorInvalidParameter,                    "kQ3ErrorInvalidParameter",
  67.     kQ3ErrorInvalidData,                        "kQ3ErrorInvalidData",
  68.     kQ3ErrorAcceleratorAlreadySet,                "kQ3ErrorAcceleratorAlreadySet",
  69.     kQ3ErrorVector3DNotUnitLength,                "kQ3ErrorVector3DNotUnitLength",
  70.     /* Object Errors */
  71.     kQ3ErrorInvalidObject,                        "kQ3ErrorInvalidObject",
  72.     kQ3ErrorInvalidObjectClass,                    "kQ3ErrorInvalidObjectClass",
  73.     kQ3ErrorInvalidObjectType,                    "kQ3ErrorInvalidObjectType",
  74.     kQ3ErrorInvalidObjectName,                    "kQ3ErrorInvalidObjectName",
  75.     kQ3ErrorObjectClassInUse,                    "kQ3ErrorObjectClassInUse",        
  76.     kQ3ErrorAccessRestricted,                    "kQ3ErrorObjectClassInUse",
  77.     kQ3ErrorMetaHandlerRequired,                "kQ3ErrorMetaHandlerRequired",
  78.     kQ3ErrorNeedRequiredMethods,                "kQ3ErrorNeedRequiredMethods",
  79.     kQ3ErrorNoSubClassType,                        "kQ3ErrorNoSubClassType",
  80.     kQ3ErrorUnknownElementType,                    "kQ3ErrorUnknownElementType",
  81.     kQ3ErrorNotSupported,                        "kQ3ErrorNotSupported",
  82.     /* Extension Errors */
  83.     kQ3ErrorNoExtensionsFolder,                    "kQ3ErrorNoExtensionsFolder",
  84.     kQ3ErrorExtensionError,                        "kQ3ErrorExtensionError",
  85.     kQ3ErrorPrivateExtensionError,                "kQ3ErrorPrivateExtensionError",
  86.     /* Geometry Errors */
  87.     kQ3ErrorDegenerateGeometry,                    "kQ3ErrorDegenerateGeometry",
  88.     kQ3ErrorGeometryInsufficientNumberOfPoints,    "kQ3ErrorGeometryInsufficientNumberOfPoints",
  89.     /* IO Errors */
  90.     kQ3ErrorEndOfFile,                            "kQ3ErrorEndOfFile",
  91.     kQ3ErrorFileCancelled,                        "kQ3ErrorFileCancelled",
  92.     kQ3ErrorInvalidMetafile,                    "kQ3ErrorInvalidMetafile",
  93.      kQ3ErrorInvalidMetafilePrimitive,            "kQ3ErrorInvalidMetafilePrimitive",
  94.      kQ3ErrorInvalidMetafileLabel,                "kQ3ErrorInvalidMetafileLabel",
  95.      kQ3ErrorInvalidMetafileObject,                "kQ3ErrorInvalidMetafileObject",
  96.      kQ3ErrorInvalidMetafileSubObject,            "kQ3ErrorInvalidMetafileSubObject",
  97.     kQ3ErrorInvalidSubObjectForObject,            "kQ3ErrorInvalidSubObjectForObject",
  98.     kQ3ErrorUnresolvableReference,                "kQ3ErrorUnresolvableReference",
  99.     kQ3ErrorUnknownObject,                        "kQ3ErrorUnknownObject",
  100.     kQ3ErrorStorageInUse,                        "kQ3ErrorStorageInUse",
  101.     kQ3ErrorStorageAlreadyOpen,                    "kQ3ErrorStorageAlreadyOpen",
  102.     kQ3ErrorStorageNotOpen,                        "kQ3ErrorStorageNotOpen",
  103.     kQ3ErrorStorageIsOpen,                        "kQ3ErrorStorageIsOpen",
  104.     kQ3ErrorFileAlreadyOpen,                    "kQ3ErrorFileAlreadyOpen",
  105.     kQ3ErrorFileNotOpen,                        "kQ3ErrorFileNotOpen",
  106.     kQ3ErrorFileIsOpen,                            "kQ3ErrorFileIsOpen",
  107.     kQ3ErrorBeginWriteAlreadyCalled,            "kQ3ErrorBeginWriteAlreadyCalled",
  108.     kQ3ErrorBeginWriteNotCalled,                "kQ3ErrorBeginWriteNotCalled",
  109.     kQ3ErrorEndWriteNotCalled,                    "kQ3ErrorEndWriteNotCalled",
  110.     kQ3ErrorReadStateInactive,                    "kQ3ErrorReadStateInactive",
  111.     kQ3ErrorStateUnavailable,                    "kQ3ErrorStateUnavailable",
  112.     kQ3ErrorWriteStateInactive,                    "kQ3ErrorWriteStateInactive",
  113.     kQ3ErrorSizeNotLongAligned,                    "kQ3ErrorSizeNotLongAligned",
  114.     kQ3ErrorFileModeRestriction,                "kQ3ErrorFileModeRestriction",
  115.     kQ3ErrorInvalidHexString,                    "kQ3ErrorInvalidHexString",
  116.     kQ3ErrorWroteMoreThanSize,                    "kQ3ErrorWroteMoreThanSize",
  117.     kQ3ErrorWroteLessThanSize,                    "kQ3ErrorWroteLessThanSize",
  118.     kQ3ErrorReadLessThanSize,                    "kQ3ErrorReadLessThanSize",
  119.     kQ3ErrorReadMoreThanSize,                    "kQ3ErrorReadMoreThanSize",
  120.     kQ3ErrorSizeMismatch,                        "kQ3ErrorSizeMismatch",
  121.     kQ3ErrorStringExceedsMaximumLength,            "kQ3ErrorStringExceedsMaximumLength",
  122.     kQ3ErrorValueExceedsMaximumSize,            "kQ3ErrorValueExceedsMaximumSize",
  123.     kQ3ErrorNonUniqueLabel,                        "kQ3ErrorNonUniqueLabel",
  124.     kQ3ErrorUnmatchedEndGroup,                    "kQ3ErrorUnmatchedEndGroup",
  125.     /* View errors */
  126.     kQ3ErrorViewNotStarted,                        "kQ3ErrorViewNotStarted",
  127.     kQ3ErrorViewIsStarted,                        "kQ3ErrorViewIsStarted",
  128.     kQ3ErrorRendererNotSet,                        "kQ3ErrorRendererNotSet",
  129.     kQ3ErrorRenderingIsActive,                    "kQ3ErrorRenderingIsActive",
  130.     kQ3ErrorImmediateModeUnderflow,                "kQ3ErrorImmediateModeUnderflow",
  131.     kQ3ErrorDisplayNotSet,                        "kQ3ErrorDisplayNotSet",
  132.     kQ3ErrorCameraNotSet,                        "kQ3ErrorCameraNotSet",
  133.     kQ3ErrorDrawContextNotSet,                    "kQ3ErrorDrawContextNotSet",
  134.     kQ3ErrorNonInvertibleMatrix,                "kQ3ErrorNonInvertibleMatrix",
  135.     kQ3ErrorRenderingNotStarted,                "kQ3ErrorRenderingNotStarted",
  136.     kQ3ErrorPickingNotStarted,                    "kQ3ErrorPickingNotStarted",
  137.     kQ3ErrorBoundsNotStarted,                    "kQ3ErrorBoundsNotStarted",
  138.     kQ3ErrorDataNotAvailable,                    "kQ3ErrorDataNotAvailable",
  139.     kQ3ErrorNothingToPop,                        "kQ3ErrorNothingToPop",
  140.     /* Renderer Errors */
  141.     kQ3ErrorUnknownStudioType,                    "kQ3ErrorUnknownStudioType",
  142.     kQ3ErrorAlreadyRendering,                    "kQ3ErrorAlreadyRendering",
  143.     kQ3ErrorStartGroupRange,                    "kQ3ErrorStartGroupRange",
  144.     kQ3ErrorUnsupportedGeometryType,            "kQ3ErrorUnsupportedGeometryType",
  145.     kQ3ErrorInvalidGeometryType,                "kQ3ErrorInvalidGeometryType",
  146.     kQ3ErrorUnsupportedFunctionality,            "kQ3ErrorUnsupportedFunctionality",
  147.     /* Group Errors */
  148.     kQ3ErrorInvalidPositionForGroup,            "kQ3ErrorInvalidPositionForGroup",
  149.     kQ3ErrorInvalidObjectForGroup,                "kQ3ErrorInvalidObjectForGroup",
  150.     kQ3ErrorInvalidObjectForPosition,            "kQ3ErrorInvalidObjectForPosition",
  151.     /* Transform Errors */
  152.     kQ3ErrorScaleOfZero,                        "kQ3ErrorScaleOfZero",
  153.     /* String Errors */
  154.     kQ3ErrorBadStringType,                        "kQ3ErrorBadStringType",
  155.     /* Attribute Errors */
  156.     kQ3ErrorAttributeNotContained,                "kQ3ErrorAttributeNotContained",
  157.     kQ3ErrorAttributeInvalidType,                "kQ3ErrorAttributeInvalidType",
  158.     /* Camera Errors */
  159.     kQ3ErrorInvalidCameraValues,                "kQ3ErrorInvalidCameraValues",
  160.     /* DrawContext Errors */
  161.     kQ3ErrorBadDrawContextType,                    "kQ3ErrorBadDrawContextType",
  162.     kQ3ErrorBadDrawContextFlag,                    "kQ3ErrorBadDrawContextFlag",
  163.     kQ3ErrorBadDrawContext,                        "kQ3ErrorBadDrawContext",
  164.     kQ3ErrorUnsupportedPixelDepth,                "kQ3ErrorUnsupportedPixelDepth",
  165.     kQ3ErrorLastError,                            "kQ3ErrorLastError"
  166. } ;
  167.  
  168.  
  169.  
  170. //-------------------------------------------------------------------------------------------
  171. // MyErrorHandler - handle warnings from QuickDraw 3d
  172. void MyErrorHandler( TQ3Error sticky, TQ3Error latest, long refCon )
  173. {
  174.     register     short     byteCount = 0;
  175.     const         short     bufsiz = 512 ;
  176.                 char     buf[bufsiz] ;
  177.                 short    index = sticky - kQ3ErrorInternalError ;
  178.     
  179.     // if the error is out of range, then just tell us that something
  180.     // "unknown" happened. Otherwise look up the error from the table.
  181.     
  182.     sprintf(&buf[1], "QuickDraw 3D Error: %d (%s)\n", 
  183.                         sticky, 
  184.                         ( sticky < kQ3ErrorInternalError || sticky > kQ3ErrorLastError ) ?  "Unknown Error Code" : errorTable[ index ].theString);
  185.         
  186.     // get the length of the c string we placed in the buffer                
  187.     for( byteCount = 1; buf[byteCount] != '\0' && byteCount < 512 ; byteCount++)
  188.         ;
  189.     // which in effect makes a pascal string
  190.     buf[0] = byteCount ;
  191.     
  192.     // and display the error string 
  193.     DebugStr( (unsigned char *)buf ) ;        
  194. }
  195.  
  196.  
  197. //-------------------------------------------------------------------------------------------
  198. // MyErrorHandler - handle warnings from QuickDraw 3d
  199. void MyWarningHandler( TQ3Warning     sticky, TQ3Warning     latest, long refCon )
  200. {
  201.     register     short     byteCount = 0;
  202.     const         short     bufsiz = 512 ;
  203.                 char     buf[bufsiz] ;
  204.                 short    stickyIndex = sticky - kQ3WarningInternalException ;
  205.                 short    latestIndex = latest - kQ3WarningInternalException ;
  206.     
  207.     // if the error is out of range, then just tell us that something
  208.     // "unknown" happened. Otherwise look up the error from the table.
  209.     
  210.     sprintf(&buf[1], "QuickDraw 3D warning: Could not %d (%s) Because %d (%s)\n", 
  211.                         sticky, 
  212.                         ( sticky < kQ3WarningInternalException || sticky > kQ3WarningLastWarning ) ? "Unknown Warning Code" : warningTable[ stickyIndex ].theString,
  213.                         latest, 
  214.                         ( latest < kQ3WarningInternalException || latest > kQ3WarningLastWarning ) ? "Unknown Warning Code" : warningTable[ latestIndex ].theString ) ;
  215.         
  216.     // get the length of the c string we placed in the buffer                
  217.     for( byteCount = 1; buf[byteCount] != '\0' && byteCount < 512 ; byteCount++)
  218.         ;
  219.         
  220.     // which in effect makes a pascal string
  221.     buf[0] = byteCount ;
  222.     
  223.     // and display the error string 
  224.     DebugStr( (unsigned char *)buf ) ;        
  225. }
  226.  
  227.